package com.boonya.rmi.order.controller;

import com.alibaba.fastjson.JSONObject;
import com.boonya.rmi.order.entity.Order;
import com.boonya.rmi.order.service.IOrder;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * @ClassName: OrderController
 * @Description: TODO(订单控制器)
 * @author: pengjunlin
 * @motto: 学习需要毅力，那就秀毅力
 * @date 2021/4/21 17:39
 */
@RestController
@RequestMapping("/order")
public class OrderController {


    @GetMapping("/getOrderById.do")
    public Order getOrderById(@Param("id") Integer id) {
        Order orderDetail = null;
        try {
            IOrder order = (IOrder) Naming.lookup("orderService");
            orderDetail = order.getOrder(id);
            System.out.println("==RMI调用服务结果==" + JSONObject.toJSONString(orderDetail));
        } catch (NotBoundException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return orderDetail;
    }
}
